package com.ctu.gzero.utils
{
	import flash.display.DisplayObjectContainer;
	import flash.display.Shape;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	public class TypeCursor extends Shape
	{
		
		private var _blinkTimer:Timer;
		
		public function TypeCursor(x:Number, y:Number, width:Number, height:Number)
		{
			super();
			this.graphics.clear();
			this.graphics.beginFill(0x000000, 1); 
			this.graphics.drawRoundRectComplex(x, y, width, height, 0, 0, 0, 0);
			this.graphics.endFill();
		}
		
		public function updateCursor(x:Number, y:Number, width:Number, height:Number):void {			
			this.alpha = 1;
			this.graphics.clear();
			this.graphics.beginFill(0x000000, 1);
			this.graphics.drawRoundRectComplex(x, y, width, height, 0, 0, 0, 0);
			this.graphics.endFill();			 
		}
		
		public function startBlinkCursor():void
		{
			if(_blinkTimer == null)
			{
				_blinkTimer = new Timer(500);
				_blinkTimer.addEventListener(TimerEvent.TIMER, blinkTimerHandler);
			}
			_blinkTimer.stop();
			_blinkTimer.start();
		}
		
		public function stopBlinkCursor():void
		{
			if(_blinkTimer)
				_blinkTimer.stop();
		}
		
		private function blinkTimerHandler(event:TimerEvent):void
		{	
			this.alpha = (this.alpha == 0)? 1: 0;
		}
		
	}
}